/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entidades;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author lcarou
 */
@Entity
@Table(name = "paiPROVINCIA")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PaiPROVINCIA.findAll", query = "SELECT p FROM PaiPROVINCIA p"),
    @NamedQuery(name = "PaiPROVINCIA.findByPais", query = "SELECT p FROM PaiPROVINCIA p WHERE p.paiPROVINCIAPK.pais = :pais"),
    @NamedQuery(name = "PaiPROVINCIA.findByCodigo", query = "SELECT p FROM PaiPROVINCIA p WHERE p.paiPROVINCIAPK.codigo = :codigo"),
    @NamedQuery(name = "PaiPROVINCIA.findByDescripcion", query = "SELECT p FROM PaiPROVINCIA p WHERE p.descripcion = :descripcion")})
public class PaiPROVINCIA implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PaiPROVINCIAPK paiPROVINCIAPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "Descripcion")
    private String descripcion;
    @JoinColumn(name = "Pais", referencedColumnName = "Codigo", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private PaiPAIS paiPAIS;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "paiPROVINCIA")
    private Collection<LegLEGAJO> legLEGAJOCollection;

    public PaiPROVINCIA() {
    }

    public PaiPROVINCIA(PaiPROVINCIAPK paiPROVINCIAPK) {
        this.paiPROVINCIAPK = paiPROVINCIAPK;
    }

    public PaiPROVINCIA(PaiPROVINCIAPK paiPROVINCIAPK, String descripcion) {
        this.paiPROVINCIAPK = paiPROVINCIAPK;
        this.descripcion = descripcion;
    }

    public PaiPROVINCIA(String pais, String codigo) {
        this.paiPROVINCIAPK = new PaiPROVINCIAPK(pais, codigo);
    }

    public PaiPROVINCIAPK getPaiPROVINCIAPK() {
        return paiPROVINCIAPK;
    }

    public void setPaiPROVINCIAPK(PaiPROVINCIAPK paiPROVINCIAPK) {
        this.paiPROVINCIAPK = paiPROVINCIAPK;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public PaiPAIS getPaiPAIS() {
        return paiPAIS;
    }

    public void setPaiPAIS(PaiPAIS paiPAIS) {
        this.paiPAIS = paiPAIS;
    }

    @XmlTransient
    public Collection<LegLEGAJO> getLegLEGAJOCollection() {
        return legLEGAJOCollection;
    }

    public void setLegLEGAJOCollection(Collection<LegLEGAJO> legLEGAJOCollection) {
        this.legLEGAJOCollection = legLEGAJOCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (paiPROVINCIAPK != null ? paiPROVINCIAPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PaiPROVINCIA)) {
            return false;
        }
        PaiPROVINCIA other = (PaiPROVINCIA) object;
        if ((this.paiPROVINCIAPK == null && other.paiPROVINCIAPK != null) || (this.paiPROVINCIAPK != null && !this.paiPROVINCIAPK.equals(other.paiPROVINCIAPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entidades.PaiPROVINCIA[ paiPROVINCIAPK=" + paiPROVINCIAPK + " ]";
    }
    
}
